import { EntityManager } from '@mikro-orm/mysql';
import { InjectEntityManager } from '@mikro-orm/nestjs';
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import { OrderJobEnrolls } from "@entities/OrderJobEnrolls";
import { JobTasks } from "@entities/JobTasks";
import { Users } from "@entities/Users";

@Injectable()
export class ApiUserMiddleware implements NestMiddleware {
  constructor(
    //@InjectEntityManager('zp')
    //private readonly zpem: EntityManager,
  ){}
  async use(req: any, res: any, next: () => void) {
    console.log(`Request...START`);

    // const job_task_ids = this.zpem.qb(OrderJobEnrolls).distinct().select('job_task_id');
    // const creator_ids = this.zpem.qb(JobTasks).distinct().select('creator_id').where({id:{'$in': job_task_ids.getKnexQuery()}});
    // const users = await this.zpem.qb(Users).select('*').where({id:creator_ids.getKnexQuery()}).execute('all');


    //return JSON.stringify(users);

    //req['user'] = users[0]; //JSON.stringify(users);
    //throw new UnauthorizedException('未授权');
    next();
    console.log(`Request...END`);
  }
}
